package com.example.threaddemo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

@Data
@ToString
@AllArgsConstructor
class User{
    String name;
    int age;
}

public class AtomicReferenceDemo {
    public static void main(String[] args) {
        User coco = new User("coco",22);
        User vs = new User("vs",18);

        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(coco);
        System.out.println(atomicReference.compareAndSet(coco, vs) + "----------" + atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(coco, vs) + "----------" + atomicReference.get().toString());
    }
}
